<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组织架构</title>
    <link rel="stylesheet" href="/css/public.css?cache=<%=Math.random()%>">
    <link  href="../../hos_manage/images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../../css/palace/organization/organization.css?a=<%=Math.random()%>">
    <link rel="stylesheet" type="text/css" href="../../css/palace/organization/tree.css?a=<%=Math.random()%>">
    <script src="../../js/jquery-1.9.1.min.js"></script>
    <script src="../../js/jquery.orgchart.min.js"></script>
    <script>
        $.ajax({
            type: 'POST',
            url: location.href,
            data: {
                act: "organizationCheck",
                hospital: "${user.hospital}",
                deptType: "20",
            },
            async: false,
            success: function(res) {
                res = JSON.parse(res);
                if (res.errcode == 0) {
                    if (res.data == 0) {
                        location.href = "import.jsp";
                    }
                } else {

                }
            },
        });
    </script>
</head>
<body id="app">
<%@ include file="../../header.jsp"%>
<!--内容-->
<div class="containerone">
    <%@ include file="../../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
        <!--右边导航下面内容-->
        <div class="organization">
            <div class="title">
                <div class="address-left show-block note">
                    <span class="hover" onclick="homePage()">首页</span>
                    <span class="left-distance">></span>
                    <span class="left-distance">组织架构列表</span>
                </div>
            </div>
            <div class="container">
                <div class="position">
                    <div class="show-block address-book-right">
                        <div class="data-form show-margin-left line">
                            <div id="left" style="display:none">
                                <ul id="organisation"></ul>
                            </div>
                            <div id="content">
                                <h1>医院架构图</h1>
                                <div id="main"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</body>
<script>
    var sb = "";
    function getUl(subDeptList) {
        if (subDeptList == null || subDeptList.length == 0) {
            return "";
        }
        sb += "<ul>";
        for (var i = 0; i < subDeptList.length; ++i) {
            var subDeptMap = subDeptList[i];
            var name = subDeptMap.deptName;
            var dataList = subDeptMap.sub_dept;
            sb += "<li>";
            if (dataList != null && dataList.length >= 1) {
                sb += name + "<img src='../../images/palace/organization/add.png'>";
            }else{
                sb += name;
            }
            getUl(dataList);
            sb += "</li>";
        }
        sb += "</ul>";
        return sb;
    }
    $.ajax({
        type: 'POST',
        url: "organization.jsp",
        data: {
            act: "organizationQuery",
            hospital: ${user.hospital},
            deptType: "20",
        },
        success: function(res) {
            res = JSON.parse(res);
            if (res.errcode == 0) {
                var data = res.data;
                if (data.length > 1) {
                    data = [{
                        deptName: "全院",
                        sub_dept: data,
                    }]
                }
                document.querySelector('#organisation').innerHTML = getUl(data);
                $("#organisation").orgChart({container: $("#main"), interactive: true, fade: false, speed: 'fast'});
                [].forEach.call(document.querySelector('table tbody').children[3].children, function(item) {
                    [].forEach.call(item.querySelectorAll('table tbody'), function(subItem) {
                        if (subItem.parentNode.parentNode.parentNode.classList.contains('lines')) {
                            return;
                        }
                        [].forEach.call(subItem.children, function(nodes) {
                            if (!nodes.classList.contains('nodes')) {
                                nodes.style.display = "none";
                            }
                        });
                    });
                })
            } else {

            }
        },
    });
    function homePage() {
        location.href = "../../index.jsp";
    }
</script>
</html>
